// index.js

const HttpReq = require("../../utils/HttpReq")

// 获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    canIUseGetUserProfile: false,
    canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'), // 如需尝试获取用户信息可改为false
    cardClientList: [
      // {
      //   id: '1677537319945232385',
      //   cardId: 2,
      //   clientId: 1,
      //   isDeleted: 0,
      //   startTime: null,
      //   endTime: null,
      //   invalid: 0,
      //   type: 3,
      //   money: 666.24,
      //   times: null,
      //   latestTime: "2023-07-13 18:16:11",
      //   clientStoreId: null,
      //   storeId: 22,
      //   consumerTimes: 2,
      //   birthday: null,
      //   name: "王霸",
      //   phoneNumber: "3454565",
      //   jifen: 0,
      //   couponList: null,
      //   days: null,
      //   patternUrl: "http://aug.coop/fjs",
      //   agreement: null
      // },
      // {
      //   id: '1677537319945232386',
      //   cardId: 2,
      //   clientId: 1,
      //   isDeleted: 0,
      //   startTime: null,
      //   endTime: null,
      //   invalid: 0,
      //   type: 3,
      //   money: 666.24,
      //   times: null,
      //   latestTime: "2023-07-13 18:16:11",
      //   clientStoreId: null,
      //   storeId: 22,
      //   consumerTimes: 2,
      //   birthday: null,
      //   name: "王霸",
      //   phoneNumber: "3454565",
      //   jifen: 0,
      //   couponList: null,
      //   days: null,
      //   patternUrl: "http://aug.coop/fjs",
      //   agreement: null
      // }
    ]
  },
  // 事件处理函数

  test(){
    var regex1 = /^https:\/\/www\.nuoyin\.cc:8081\/img\/store\/[0-9]+\.png$/;
    var regex2 = /^https:\/\/www\.nuoyin\.cc:8081\/img\/store\/([0-9]+)\.png$/;
    var ss = "https://www.nuoyin.cc:8081/img/store/1657413650.png"
    if(regex1.test(ss)){
      console.log('测试通过')
      var match = ss.match(regex2);
      console.log(match[1])
    }
  },

  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad() {
    wx.setNavigationBarTitle({
      title: '诺银会员' // 替换成你想要设置的标题
    })
    var that = this
    let url = app.globalData.hostIp + '/weixin/getAllCardClientByClientId?clientId=' + app.globalData.userInfo.id
    HttpReq.httpsResquest(url, null, 'GET').then(res=>{
      console.log(res)
      if(res.code == 1){
        that.setData({
          cardClientList: res.data
        })
      }
    })
  },
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
  getUserInfo(e) {
    // 不推荐使用getUserInfo获取用户信息，预计自2021年4月13日起，getUserInfo将不再弹出弹窗，并直接返回匿名的用户个人信息
    console.log(e)
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  //进入详情页
  toCardClientDetail(e){
    var cardClientId = e.currentTarget.dataset.item
    wx.navigateTo({
      url: '/pageA/pages/cardDetail/index?id=' + cardClientId,
    })
    // wx.navigateTo({
    //   url: '/pages/cardDetail/index?id=' + cardClientId,
    // })
    return
    wx.redirectTo({
      url: '/pages/myCardClient/myCardClient?cardClientId=' + cardClientId,
    })
  },
  //详情
  detail(){
      wx.navigateTo({
        url:  "/pages/cardDetail/index",
      })
  }
})
